package com.cn.kehong.controller;

import com.cn.kehong.api.IProductGzPeriodService;
import com.cn.kehong.api.IProductSaojiePeriodService;
import com.cn.kehong.domain.ProductGzPeriod;
import com.cn.kehong.domain.ProductSaojieJob;
import com.cn.kehong.domain.ProductSaojiePeriod;
import com.cn.kehong.utils.CommonUtil;
import com.cn.kehong.utils.JsonResponse;
import com.cn.kehong.utils.QueryForm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/shaojie")
public class ProductShaojiePeriodController {

    @Autowired
    private IProductSaojiePeriodService productSaojiePeriodService;


    @RequestMapping("/getProductSaojiePeriodList/{frontToken}")
    @ResponseBody
    public JsonResponse<List<ProductSaojiePeriod>> getProductSaojiePeriodList(QueryForm queryForm, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<List<ProductSaojiePeriod> > response = new JsonResponse<List<ProductSaojiePeriod> >();
        List<ProductSaojiePeriod> lists = productSaojiePeriodService.getProductSaojiePeriodList(queryForm);
        response.setResult(lists);
        response.setSuccess(true);
        return  response;
    }

    @RequestMapping("/getProductSaojieJobList/{frontToken}")
    @ResponseBody
    public JsonResponse<List<ProductSaojieJob>> getProductSaojieJobList(QueryForm queryForm, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<List<ProductSaojieJob> > response = new JsonResponse<List<ProductSaojieJob> >();
        List<ProductSaojieJob> lists = productSaojiePeriodService.getProductSaojieJobList(queryForm);
        response.setResult(lists);
        response.setSuccess(true);
        return  response;
    }

    @RequestMapping("/getProductSaojieJobsById/{frontToken}")
    @ResponseBody
    public JsonResponse<List<ProductSaojieJob>> getProductSaojieJobsById(String saojieId, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<List<ProductSaojieJob> > response = new JsonResponse<List<ProductSaojieJob> >();
        List<ProductSaojieJob> lists = productSaojiePeriodService.getProductSaojieJobsById(saojieId);
        response.setResult(lists);
        response.setSuccess(true);
        return  response;
    }

    @RequestMapping("/getGzToSaojiePeriodDatas/{frontToken}")
    @ResponseBody
    public JsonResponse<List<ProductSaojiePeriod>> getGzToSaojiePeriodDatas(String factoryName, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<List<ProductSaojiePeriod> > response = new JsonResponse<List<ProductSaojiePeriod> >();
        List<ProductSaojiePeriod> lists = productSaojiePeriodService.getGzToSaojiePeriodDatas(factoryName);
        response.setResult(lists);
        response.setSuccess(true);
        return  response;
    }

    //进窑炉
    @RequestMapping("/updateGzPeriodEnterYaolu/{frontToken}")
    @ResponseBody
    public JsonResponse<String> updateGzPeriodEnterYaolu(ProductSaojiePeriod productGzPeriod, @PathVariable(value =  "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = productSaojiePeriodService.updateGzPeriodEnterYaolu(productGzPeriod);
        return CommonUtil.getResponseData(response,result);
    }

    @RequestMapping("/updateBatchProductSaojieJob/{frontToken}")
    @ResponseBody
    public JsonResponse<String> updateBatchProductSaojieJob(@RequestBody ProductSaojiePeriod productSaojiePeriod, @PathVariable(value =  "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = productSaojiePeriodService.updateBatchProductSaojieJob(productSaojiePeriod);
        return CommonUtil.getResponseData(response,result);
    }

}
